package com.iwhalecloud.uncc.archiver.impl;

import com.iwhalecloud.uncc.archiver.Archiver;
import com.iwhalecloud.uncc.common.DataSourceHelp;
import com.iwhalecloud.uncc.common.SpringContext;
import com.iwhalecloud.uncc.model.InsCollectService;
import com.iwhalecloud.uncc.service.ArchiverService;
import lombok.extern.slf4j.Slf4j;

/**
 * @author zq
 * @date 2021/10/20 11:08
 * @description InsCollectServiceArchiver
 */
@Slf4j
public class InsCollectServiceArchiver implements Archiver {

    private ArchiverService<InsCollectService> insCollectServiceArchiverService =
            (ArchiverService<InsCollectService>) SpringContext.getContext().getBean("insCollectServiceArchiverService");

    private DataSourceHelp dataSourceHelp =
            (DataSourceHelp) SpringContext.getContext().getBean("dataSourceHelp");

    /**
     * 归档 InsCollectService 关联 每个分片启动一个线程
     */
    @Override
    public void archive() {
        if (log.isInfoEnabled()) {
            log.info("InsCollectServiceArchiver 提交归档任务...");
        }
        dataSourceHelp.getOnlineDatasource().forEach(i->insCollectServiceArchiverService.archive(i.getCode()));

    }

}
